<?php
namespace App\Traits;

trait ReturnTrait 
{
    protected static function success($data = [], $msg = 'success', $code = 0)
    {
        return self::retData($code, $msg, $data);
    }

    protected static function error($msg = 'fail', $data = [], $code = 1) 
    {
        return self::retData($code, $msg, $data);
    }

    protected static function retData($code, $msg, $data)
    {
        return [
            'code' => $code,
            'msg' => $msg,
            'data' => $data,
        ];
    }

    public static function isSuccess($resp, $sucCode = 0)
    {
        return isset($resp['code']) && intval($resp['code']) === intval($sucCode);
    }

    public static function isError($resp, $sucCode = 0)
    {
        return !self::isSuccess($resp, $sucCode);
    }
}